package JSE_03.Demo06;

import java.util.Scanner;

public class Demo06RegisterException {
    static String[] usernames={"张三","李四","王五"};
    public static void main(String[] args) /*throws RegisterException*/{
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入您要注册的用户名:");
        String username=sc.next();
        checkUserName(username);
    }

    public static void checkUserName(String username) /*throws RegisterException*/{
        for(String name:usernames){
            if(name.equals(username)){
                try{
                    System.out.println("执行了try");
                    throw new RegisterException("亲,该用户已经被注册!");
                }catch (RegisterException e){
                    System.out.println("执行了catch");
                    e.printStackTrace();
                    return ;
                }
            }
        }

        System.out.println("恭喜您，注册成功");
    }
}
